﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Diagnostics;

namespace MVCFoto.BLL
{
    public class MVCFotoException : Exception
    {
         private readonly MVCFotoComponent _component;

        
        public MVCFotoComponent Component
        {
            get { return _component; }
        }

        
        public override string Message
        {
            get
            {
                return String.Format("MVCFoto Exception ({0}): {1}", Component, base.Message);
            }
        }

        public MVCFotoException(string message) : this(message,null) 
        { 
        }

        public MVCFotoException(string message, Exception innerException)
            : base(message, innerException)
        {
            // get the calling assembly
            Assembly assembly = new StackFrame(1).GetMethod().ReflectedType.Assembly;
            string assemblyName = assembly.FullName.Split(",".ToCharArray())[0];
            // try to determine the component
            try
            {
                string componentName = assemblyName.ToLower().Replace("mvcfoto.", String.Empty);
                _component = (MVCFotoComponent)Enum.Parse(typeof(MVCFotoComponent), componentName, true);
            }
            // do nothing if parsing fails, default value is MVCComponent.External
            catch (ArgumentException) { }
        }
       

    }

    /// <summary>
    /// Enum of all MVCFoto components
    /// </summary>
    public enum MVCFotoComponent
    {
        /// <summary>Unknown component</summary>
        External,
        /// <summary>Business logic component</summary>
        BLL,
        /// <summary>DALFactory component</summary>
        DALFactory,
        /// <summary>IDAL component</summary>
        IDAL,
        /// <summary>Model component</summary>
        Model,
        /// <summary>sql server data access component</summary>
        SQLServerDAL,
        /// <summary>web component</summary>
        Web
       
    }
    
}
